// 全站表格列配置 - 统一列宽定义
// 用于解决表头与内容错位问题

export interface BaseColumn {
  dataIndex?: string;
  title: string;
  key: string;
  width: number;
  className?: string;
  ellipsis?: boolean;
}

// 邀请管理页面列配置
export const INVITES_COLUMNS: BaseColumn[] = [
  {
    title: '邀请人',
    key: 'inviter',
    width: 240,
    className: 'cell--inviter',
    ellipsis: true
  },
  {
    title: '被邀请人',
    key: 'invitee', 
    width: 240,
    className: 'cell--invitee',
    ellipsis: true
  },
  {
    title: '邀请状态',
    key: 'status',
    width: 120,
    className: 'cell--status'
  },
  {
    title: '邀请时间',
    key: 'inviteTime',
    width: 160,
    className: 'cell--time'
  },
  {
    title: '操作',
    key: 'action',
    width: 140,
    className: 'cell--actions'
  }
];

// 优惠券管理页面列配置
export const COUPONS_COLUMNS: BaseColumn[] = [
  {
    title: '优惠券信息',
    key: 'couponInfo',
    dataIndex: 'name',
    width: 320,
    className: 'cell--coupon-info',
    ellipsis: true
  },
  {
    title: '类型',
    key: 'type',
    dataIndex: 'type',
    width: 100,
    className: 'cell--type'
  },
  {
    title: '面值',
    key: 'value',
    dataIndex: 'value',
    width: 120,
    className: 'cell--value'
  },
  {
    title: '使用条件',
    key: 'condition',
    dataIndex: 'minAmount',
    width: 140,
    className: 'cell--condition'
  },
  {
    title: '有效期',
    key: 'validity',
    dataIndex: 'startTime',
    width: 160,
    className: 'cell--validity'
  },
  {
    title: '状态',
    key: 'status',
    dataIndex: 'status',
    width: 100,
    className: 'cell--status'
  },
  {
    title: '操作',
    key: 'action',
    width: 140,
    className: 'cell--actions'
  }
];

// 菜单管理页面列配置
export const MENU_COLUMNS: BaseColumn[] = [
  {
    title: 'ID',
    key: 'id',
    dataIndex: 'id',
    width: 80,
    className: 'cell--id'
  },
  {
    title: '图片',
    key: 'image',
    dataIndex: 'image',
    width: 72,
    className: 'cell--image'
  },
  {
    title: '菜品名称',
    key: 'name',
    dataIndex: 'name',
    width: 160,
    className: 'cell--name',
    ellipsis: true
  },
  {
    title: '描述',
    key: 'description',
    dataIndex: 'description',
    width: 280,
    className: 'cell--description',
    ellipsis: true
  },
  {
    title: '配料',
    key: 'ingredients',
    dataIndex: 'ingredients',
    width: 200,
    className: 'cell--ingredients',
    ellipsis: true
  },
  {
    title: '价格',
    key: 'price',
    dataIndex: 'price',
    width: 120,
    className: 'cell--price'
  },
  {
    title: '评分',
    key: 'rating',
    dataIndex: 'rating',
    width: 80,
    className: 'cell--rating'
  },
  {
    title: '分类',
    key: 'category',
    dataIndex: 'category',
    width: 100,
    className: 'cell--category'
  },
  {
    title: '状态',
    key: 'status',
    dataIndex: 'status',
    width: 100,
    className: 'cell--status'
  },
  {
    title: '库存',
    key: 'stock',
    dataIndex: 'stock',
    width: 80,
    className: 'cell--stock'
  },
  {
    title: '销量',
    key: 'sales',
    dataIndex: 'sales',
    width: 80,
    className: 'cell--sales'
  },
  {
    title: '热门',
    key: 'isHot',
    dataIndex: 'isHot',
    width: 80,
    className: 'cell--hot'
  },
  {
    title: '更新时间',
    key: 'updateTime',
    dataIndex: 'updateTime',
    width: 150,
    className: 'cell--time'
  },
  {
    title: '操作',
    key: 'action',
    width: 140,
    className: 'cell--actions'
  }
];

// 计算表格总宽度
export const getTableWidth = (columns: BaseColumn[]): number => {
  return columns.reduce((total, col) => total + col.width, 0);
};

// 生成列宽样式对象
export const generateColumnStyles = (columns: BaseColumn[]): Record<string, React.CSSProperties> => {
  const styles: Record<string, React.CSSProperties> = {};
  columns.forEach((col) => {
    styles[col.key] = {
      width: `${col.width}px`,
      minWidth: `${col.width}px`,
      maxWidth: `${col.width}px`
    };
  });
  return styles;
};